package net.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串处理工具类
 * 
 * @author 孙树林
 * 
 */
public class StringUtils {

	public static String COMMA_SYMBOL = "\\,";

	public static String FULl_STOP = "\\.";

	public static String SEMICOLON = "\\;";

	public static String START = "*";

	/**
	 * 字符串内容比较;不区分大小写.
	 * 
	 * @param source
	 * @param target
	 * @return boolean
	 */
	public static boolean equalsign(String source, String target) {
		if (source.equalsIgnoreCase(target)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 字符串内容比较;区分大小写.
	 * 
	 * @param source
	 * @param target
	 * @return boolean
	 */
	public static boolean equalsignIgnoreCase(String source, String target) {
		if (source.equals(target)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 字符串开头判断
	 * 
	 * @param source
	 * @param partten
	 * @return
	 */
	public static boolean startswith(String source, String partten) {
		return (source.startsWith(partten));
	}

	/**
	 * 字符串结束判断
	 * 
	 * @param source
	 * @param partten
	 * @return
	 */
	public static boolean endsWith(String source, String partten) {
		return (source.endsWith(partten));
	}

	/**
	 * 查询字符串的位置
	 * 
	 * @param source
	 * @param partten
	 * @return
	 */
	public static int indexOf(String source, String partten) {
		return source.indexOf(partten);
	}

	/**
	 * 字符串非空校验
	 * 
	 * @param source
	 * @return
	 */
	public static boolean isNotEmpty(String source) {
		return (source != null && !source.equals("")) ? true : false;
	}

	/**
	 * 字符串分割
	 * 
	 * @param source
	 * @param style
	 * @return
	 */
	public static String[] split(String source, String style) {
		return source == null ? null : source.split(style);
	}

	/**
	 * 字符串匹配
	 * 
	 * @param str
	 * @param partten
	 * @return
	 */
	public static boolean match(String str, String partten) {
		Pattern p = Pattern.compile(partten);
		Matcher m = p.matcher(str);
		if (m.find()) {
			return true;
		}
		return false;
	}

}
